package com.lyncs.ods.resp;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.lyncs.ods.modules.txn.model.DeliverInfo;
import com.lyncs.ods.modules.txn.model.TagInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author alex
 * @date 2022/2/26 20:26
 * @description
 */
@Data
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@Accessors(chain = true)
public class DeliverDetailInfoResp {

    @ApiModelProperty(value = "交付单ID")
    private Long deliverId;

    @ApiModelProperty(value = "交付单名称")
    private String deliverName;

    @ApiModelProperty(value = "已结算次数")
    private Integer totalSettledCount;

    @ApiModelProperty(value = "关联订单数")
    private Long relatedOrderCount;

    @ApiModelProperty(value = "总金额")
    private String totalAmount;

    @ApiModelProperty(value = "状态")
    private Integer status;

    @ApiModelProperty(value = "交付单开始时间")
    private LocalDate startDate;

    @ApiModelProperty(value = "货币")
    private String currency;

    @ApiModelProperty(value = "是否置顶。true;false")
    private Boolean top;

    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "卖方公司信息")
    private CompanyShortInfoResp sellerCompanyInfo;

    @ApiModelProperty(value = "买方公司信息")
    private CompanyShortInfoResp buyerCompanyInfo;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "账款部分结算类别数")
    private Integer partialCount;

    @ApiModelProperty(value = "账款全部结算类别数")
    private Integer settledCount;

    @ApiModelProperty(value = "账款未结算类别数")
    private Integer unsettledCount;

    @ApiModelProperty(value = "创建者用户名称")
    private String creatorName;

    @ApiModelProperty(value = "更新时间")
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "创建者用户所属公司ID")
    private Long creatorCompanyId;

    @ApiModelProperty("交付地点")
    private String location;

    @ApiModelProperty("航班号")
    private String flightNumber;

    @ApiModelProperty("启运地")
    private String departure;

    @ApiModelProperty("目的地")
    private String destination;

    @ApiModelProperty("自定义字段信息")
    private String customFields;

    @ApiModelProperty("附件")
    private String attachment;

    @ApiModelProperty(value = "sku info")
    private List<SkuInfo> skuInfoList;

    @ApiModelProperty(value = "账款 信息")
    private List<DeliverBillInfo> billInfos;

    @Data
    @Accessors(chain = true)
    @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
    public static class SkuInfo {

        @ApiModelProperty(value = "关联的订单ID")
        private Long orderId;

        @ApiModelProperty(value = "订单名称")
        private String orderName;

        @ApiModelProperty(value = "关联的skuID")
        private Long skuId;

        @ApiModelProperty(value = "sku内部货号")
        private String innerCode;

        @ApiModelProperty(value = "sku名称")
        private String name;

        @ApiModelProperty(value = "sku图片")
        private String imgUrl;

        @ApiModelProperty(value = "本次交易本SKU需要交付数量")
        private BigDecimal totalCount;

        @ApiModelProperty(value = "已交付商品数")
        private BigDecimal deliveredCount;

        @ApiModelProperty(value = "待交付商品数")
        private BigDecimal undeliveredCount;

        @ApiModelProperty(value = "总价")
        private String totalAmount;

        @ApiModelProperty(value = "单价")
        private String amount;

        @ApiModelProperty(value = "单位")
        private String unit;

        @ApiModelProperty(value = "备注")
        private String remark;

        @ApiModelProperty("标签信息")
        private List<TagInfo> tagInfos;

        @ApiModelProperty(value = "sku属性")
        private Map<String, String> skuAttrs;
    }

    @Data
    @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
    public static class DeliverBillInfo {

        @ApiModelProperty(value = "账款ID")
        private Long billId;

        @ApiModelProperty(value = "账款名称")
        private String name;

        @ApiModelProperty("款项金额")
        private BigDecimal totalAmount;

        @ApiModelProperty(value = "已结算金额")
        private BigDecimal settledAmount;

        @ApiModelProperty(value = "未结算金额")
        private BigDecimal unsettledAmount;

        @ApiModelProperty("款项数")
        private Integer categoryCount;

        @ApiModelProperty(value = "款项 信息")
        private List<DeliverFeeInfo> feeInfos;

        @ApiModelProperty("创建时间")
        private LocalDateTime createTime;

    }

    @Data
    @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
    public static class DeliverFeeInfo {

        @ApiModelProperty(value = "款项ID")
        private Long feeId;

        @ApiModelProperty(value = "款项名称")
        private String feeName;

        @ApiModelProperty(value = "款项金额")
        private String feeAmount;

        @ApiModelProperty("备注")
        private String remark;
    }

    public DeliverDetailInfoResp(DeliverInfo deliverInfo) {
        this.setDeliverId(deliverInfo.getId())
                .setDeliverName(deliverInfo.getDeliverName())
                .setStatus(deliverInfo.getStatus())
                .setStartDate(deliverInfo.getStartDate())
                .setCreateTime(deliverInfo.getCreateTime())
                .setRemark(deliverInfo.getRemark())
                .setUpdateTime(deliverInfo.getUpdateTime())
                .setCreatorCompanyId(deliverInfo.getCreatorCompanyId())
                .setLocation(deliverInfo.getLocation())
                .setFlightNumber(deliverInfo.getFlightNumber())
                .setDeparture(deliverInfo.getDeparture())
                .setDestination(deliverInfo.getDestination())
                .setCurrency(deliverInfo.getCurrency())
                .setAttachment(deliverInfo.getAttachment())
                .setCustomFields(deliverInfo.getCustomFields());
    }
}
